<?php
require_once($application_folder."/controllers/navigator.php");
class Articles extends navigator 
{

    function __construct()
    {
        parent::__construct(); 
        $this->load->model('datam');
    } 

    function index(){
        $this->getArticles();
    }

    function getArticles(){

        

        $res['columns'] = $this->datam->getColumns();
        $res['tickerNews'] = $this->datam->getArticlesColsSubcolsWithDefaultMediaByTags(1, '0,2');
        $res['last'] = $this->datam->getArticlesColsSubcolsWithDefaultMediaByTags(1, 1);
        $res['four_side'] = $this->datam->getArticlesColsSubcolsWithDefaultMediaByTags(1, 5);             
        $res['articleImagesMain'] = $this->datam->getMediaImagesForArticle($res['last'][0]['id']);
        
        $res['articles_line'] = $this->datam->getArticlesColsSubcolsWithDefaultMedia();             
        
        $res['title'] = 'Dobrodosli';         
        //$res['articles_today1'] =  $this->datam->getArticlesColsSubcolsWithDefaultMediaByTags(1,'5,6');
        //$res['articles_sevenday'] =  $this->datam->getArticlesColsSubcolsWithDefaultMediaByTags(1,'7,4');
        $res['articles_today1'] =  $this->datam->getArticlesPastTime(1,6,1);
        $res['articles_sevenday'] =  $this->datam->getArticlesPastTime(1,4,7);
        $res['articles_top_comments'] =  $this->datam->getArticlesTopCommnets(1,6);
        
        $res['caricature'] =  $this->datam->getCaricature();
        $res['wordofday'] =  $this->datam->getWordofday();
        $res['recipeofday'] =  $this->datam->getRecipeofday();
        $res['horoscope'] =  $this->datam->getHoroscope();
        $res['signs'] =  $this->datam->getHoroscopeSigns();
        

        $this->core_site('site', $res, 'home');

    }

    function newsFeed($subcolumnId){

        $this->load->model('datam');
        $res['feed'] = $this->datam->getNewsFeed($subcolumnId);
        //echo json_encode($this->load->view('article/newsFeed', $res, TRUE));
        if(count($res['feed'])>0){
            $this->load->view('article/newsFeed', $res);    
        }else{
            $this->load->view('article/noNewsFeed');
        }        

    } 
    
    /**
     * 
     * Ajax poziva ovu metodu da dobije nove podatke za scroller
     * @param int $column - id kategorije clanaka
     * @param int $subcolumn - id podkategorije clanaka
     */
    public function getArticlesForScrollerOnArticlePage($column,$subcolumn)
    {
    	
    	$articles_line = $this->datam->getArticlesForScroller($column,$subcolumn);
    	$i=1;
    	
    	$this->load->helper('character');
    	//print_r($articles_line);
    	///*
    	$cloned= "";
    	if(count($articles_line)>0){
    	while($i<12){ 
    	  if($i>6) $cloned =  " cloned hacked-cloned"; 
    	  foreach ($articles_line as $line_article) {
    		
    		$link = base_url().sredinaslov($line_article['title'],$line_article['id'],$line_article['sName']);

                $cssBgImageOverwrite = "";
                $cssBorderOverwrite = "";

                switch($line_article['mType']){

                    case 'yt':
                        $cssBgImageOverwrite = ' nadnaslovVid';
                        $cssBorderOverwrite = ' kockaimgVid';
                        break;
                }
                
                //$hide = "";
				//if($line_article['id']==188) $hide = " style='display:none;' ";
                echo "<div class='kocka2 {$cloned}' id='{$line_article['id']}' >"; //{$hide}

               //debug
               ///$link = "";
			
            echo "

            <div class='kocka2img{$cssBorderOverwrite}'>
                <a class='mPhoto' href='{$link}'>";

                        switch($line_article['mType']){
                            case 'img':
                            
                            echo "<img src='".base_url().'cache/'.$this->img_map->showImage($line_article['mFile'],158,105,"exacttop")."' alt='".$line_article['caption']."' title='".$line_article['caption']."' width='158' height='105' />";
                            
                                break;

                            case 'yt':
                            
                            echo "<img src='".base_url().'cache/'.$this->img_map->showImage($line_article['mFile'].".jpg",158,105,"exacttop")."' alt='".$line_article['caption']."' title='".$line_article['caption']."' width='158' height='105' />";
                            
                                break;
                        }

                    echo "

                    <div class='nadnaslov{$cssBgImageOverwrite}'>";
                    
                            if ($line_article['mType']=='yt'){
                                echo 'Video';
                            }else{
                                if(strlen($line_article['uptitle'])>25){
                                    echo $line_article['cName'];
                                }else echo $line_article['uptitle']; 
                            }

                    echo "</div>
                </a>

            </div>
            ";

                echo '<div style="clear: both;"></div>';
                echo "<h4><a class='mLink' href='$link'>{$line_article['title']}</a></h4>";

                echo "</div>";

                $i++;
    	
    		//echo $line_article['title'];
    		}
    	}// end while
    	}//end if
    	//else
    	//echo "<div class='kocka2'>Nema clanaka.</div>";
    	
    }
       

}